package com.scsj.supermarket.view.activity.walletmodel;

import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSONObject;
import com.scsj.supermarket.R;
import com.scsj.supermarket.base.MyWalletBase;
import com.scsj.supermarket.bean.GetOwnTreasureInfoBean;
import com.scsj.supermarket.presenter.MyWalletPresenter;
import com.scsj.supermarket.utils.SkipUtils;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;
import com.zaaach.citypicker.CityPicker;
import com.zaaach.citypicker.adapter.OnPickListener;
import com.zaaach.citypicker.model.City;
import com.zaaach.citypicker.model.HotCity;
import com.zaaach.citypicker.model.LocateState;
import com.zaaach.citypicker.model.LocatedCity;

import java.util.ArrayList;
import java.util.List;

import okhttp3.RequestBody;

/**
 * 我的钱包首页
 */
public class MyWalletActivity extends BaseActivity implements View.OnClickListener, MyWalletBase.IView {

    private TextView mMoneyTv;
    private RelativeLayout mMyRechargeRl;
    private RelativeLayout mMyWithdrawRl;
    /**
     * 解绑银行卡
     */
    private TextView mBankCardStateTv;
    private RelativeLayout mMyBankCard;
    private RelativeLayout mMoneyDetailLay;
    private RelativeLayout mMyShareprofit;
    /**
     * 修改
     */
    private TextView mPayPswStateTv;
    private RelativeLayout mMyPasswordLay;
    /**
     * 未认证
     */
    private TextView mAuthenticationStateTv;
    private RelativeLayout mRealNameAuthenticationRl;
    private RelativeLayout mMain;
    private MyWalletPresenter presenter;
    private double balance;
    private double rate;
    private String idcard;
    private int isSet;
    private int isBindBankCard;


    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_my_wallet);
//        ScreenAdapterTools.getInstance().loadView((ViewGroup) getWindow().getDecorView());
        //ScreenAdapterTools.getInstance().reset(this);//如果希望android7.0分屏也适配的话,加上这句

        presenter = new MyWalletPresenter(this);

        initToolbar();
        setToolbarTitle("我的钱包");
        hasBack(true);
        initView();

        JSONObject object = new JSONObject();
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), object.toString());
        presenter.deliverGetOwnTreasureInfoData(body);
    }

    @Override
    protected void initView() {

        mMoneyTv = (TextView) findViewById(R.id.money_tv);
        mMyRechargeRl = (RelativeLayout) findViewById(R.id.my_recharge_rl);
        mMyRechargeRl.setOnClickListener(this);
        mMyWithdrawRl = (RelativeLayout) findViewById(R.id.my_withdraw_rl);
        mMyWithdrawRl.setOnClickListener(this);
        mBankCardStateTv = (TextView) findViewById(R.id.bank_card_state_tv);
        mMyBankCard = (RelativeLayout) findViewById(R.id.my_bank_card);
        mMyBankCard.setOnClickListener(this);
        mMoneyDetailLay = (RelativeLayout) findViewById(R.id.money_detail_Lay);
        mMoneyDetailLay.setOnClickListener(this);
        mMyShareprofit = (RelativeLayout) findViewById(R.id.my_shareprofit);
        mMyShareprofit.setOnClickListener(this);
        mPayPswStateTv = (TextView) findViewById(R.id.pay_psw_state_tv);
        mMyPasswordLay = (RelativeLayout) findViewById(R.id.my_password_Lay);
        mMyPasswordLay.setOnClickListener(this);
        mAuthenticationStateTv = (TextView) findViewById(R.id.authentication_state_tv);
        mRealNameAuthenticationRl = (RelativeLayout) findViewById(R.id.real_name_authentication_rl);
        mRealNameAuthenticationRl.setOnClickListener(this);
        mMain = (RelativeLayout) findViewById(R.id.main);

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.my_bank_card://银行卡
                if (isBindBankCard == 0) {//未绑定银行卡
                    SkipUtils.toAddBankCard(this);
                } else {
                    SkipUtils.toAddBankPicPage(this);
                }
                break;
            case R.id.money_detail_Lay: //余额明细
                SkipUtils.toBalance(this);
                break;
            case R.id.my_shareprofit://分润账单
                SkipUtils.toShareProfit(this);
                break;
            case R.id.my_password_Lay://支付密码设置
                if (isSet == 0) {//未设置支付密码
                    SkipUtils.toPhoneCodeVerification(this, "pay");
                } else {
                    SkipUtils.toChangePaymentPwd(this);
                }
                break;
            case R.id.real_name_authentication_rl:
                if (TextUtils.isEmpty(idcard)) {//未实名认证
                    SkipUtils.toRealNameAuthentication(this);
                } else {
                    SkipUtils.toRealNameAuthenticationShow(this);
                }
                break;
            case R.id.my_recharge_rl://我要充值
                SkipUtils.toMineRecharge(this);
                break;
            case R.id.my_withdraw_rl://我要提现
                SkipUtils.toCashBalance(this, balance, rate);
                break;


        }
    }


    @Override
    public void vGetOwnTreasureInfoSuccessMsg(String s, GetOwnTreasureInfoBean bean) {
        balance = bean.getData().getBalance();
        rate = bean.getData().getRate();
        //身份证,如果为null则未实名
        idcard = bean.getData().getIdcard();
        //是否设置支付密码:0未设置1已设置
        isSet = bean.getData().getIsSet();
        //是否绑定银行卡:0否;1是
        isBindBankCard = bean.getData().getIsBindBankCard();

        mMoneyTv.setText(balance + "");

        if (TextUtils.isEmpty(idcard)) {
            mAuthenticationStateTv.setText("未认证");
        } else {
            mAuthenticationStateTv.setText("已认证");
        }

        if (isSet == 0) {//未设置支付密码
            mPayPswStateTv.setText("设置");
        } else if (isSet == 1) {
            mPayPswStateTv.setText("修改");
        }

        if (isBindBankCard == 0) {
            mBankCardStateTv.setVisibility(View.VISIBLE);
            mBankCardStateTv.setText("绑定银行卡");
        } else if (isBindBankCard == 1) {
            mBankCardStateTv.setVisibility(View.INVISIBLE);
        }

    }

    @Override
    public void showErrorMsg(String s) {

    }
}
